package com.iflytek.jobs.app;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iflytek.jobs.service.domain.JobDelivery;
import com.iflytek.jobs.service.service.IJobDeliveryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 简历投递记录Controller
 * 
 * @author chenhs
 * @date 2023-04-26
 */
@RestController
@RequestMapping("/app/jobdelivery")
public class AppJobDeliverController extends BaseController
{
    @Autowired
    private IJobDeliveryService jobDeliveryService;

    /**
     * 查询简历投递记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JobDelivery jobDelivery)
    {
        startPage();
        jobDelivery.setMapParams();
        List<JobDelivery> list = jobDeliveryService.selectJobDeliveryList(jobDelivery);
        return getDataTable(list);
    }


    /**
     * 获取简历投递记录详细信息
     */
    @GetMapping(value = "/{jdId}")
    public AjaxResult getInfo(@PathVariable("jdId") Integer jdId)
    {
        return success(jobDeliveryService.selectJobDeliveryByJdId(jdId));
    }

    /**
     * 新增简历投递记录
     */
    @PostMapping("/add")
    @PreAuthorize("@ss.notRole('demo')")
    public AjaxResult add(@RequestBody JobDelivery jobDelivery)
    {
    	jobDelivery.setCreateBy(super.getUsername());
    	int i = jobDeliveryService.insertJobDelivery(jobDelivery);
    	if(i==-1) {
    		return AjaxResult.warn("你的简历没有指导记录，无法投递岗位");
    	}else if(i==-2) {
    		return AjaxResult.warn("你的已投递过该岗位");
    	}else {
    		return toAjax(i);    		
    	}
    }

    /**
     * 修改简历投递记录
     */
    @PostMapping("/update")
    @PreAuthorize("@ss.notRole('demo')")
    public AjaxResult edit(@RequestBody JobDelivery jobDelivery)
    {
        return toAjax(jobDeliveryService.updateJobDelivery(jobDelivery));
    }

    /**
     * 删除简历投递记录
     */
	@GetMapping("/delete/{jdId}")
    @PreAuthorize("@ss.notRole('demo')")
    public AjaxResult remove(@PathVariable Integer jdId)
    {
		int i = jobDeliveryService.deleteJobDeliveryByJdId(jdId);
		if(i==-1) {
			return AjaxResult.warn("该简历已经发往企业，无法撤回");
		}else {
			return toAjax(i);
		}
    }
}



